package it.blueocean.acanto.platform.model;

import it.blueocean.acanto.platform.model.common.ABaseEntity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "TA_FAMIGLIE")
public class Famiglia extends ABaseEntity 
{
	private static final long serialVersionUID = 4521192060211479610L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID_FAMIGLIA", unique = true, nullable = false)
	private long id;

	@Column(name = "CDG", unique = true, length = 255, nullable = false)
	private String cdg;

	@Column(name = "PASSWORD", length = 45, nullable = false)
	private String password;

	@Column(name = "COGNOME_REFERENTE", length = 50)
	private String cognomeReferente;

	@Column(name = "NOME_REFERENTE", length = 50)
	private String nomeReferente;

	@Column(name = "NOTE")
	private String note;

	@Column(name = "ASSENTE_DAL", nullable = true)
	@Temporal(TemporalType.DATE)
	private Date assenteDal;

	@Column(name = "ASSENTE_AL", nullable = true)
	@Temporal(TemporalType.DATE)
	private Date assenteAl;

	public Famiglia()
	{
	}

	public Famiglia(Famiglia famiglia)
	{
		this.setId(famiglia.getId());
		this.setCdg(famiglia.getCdg());
		this.setNomeReferente(famiglia.getNomeReferente());
		this.setCognomeReferente(famiglia.getCognomeReferente());
		this.setNote(famiglia.getNote());
		this.setPassword(famiglia.getPassword());
		this.setAssenteAl(famiglia.getAssenteAl());
		this.setAssenteDal(famiglia.getAssenteDal());
		this.setCreated(famiglia.getCreated());
		this.setCreator(famiglia.getCreator());
		this.setModified(famiglia.getModified());
		this.setModifier(famiglia.getModifier());
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cdg == null) ? 0 : cdg.hashCode());
		result = prime * result + ((password == null) ? 0 : password.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if(obj instanceof Famiglia)
		{
			Famiglia an = (Famiglia) obj;
			return an.getCdg().equalsIgnoreCase(this.getCdg()) && an.getPassword().equalsIgnoreCase(this.getPassword());
		}
		else
			return false;
	}

	/**
	 * @return a <code>String</code> representation of this object.
	 */
	@Override
	public String toString()
	{
		final String TAB = "    ";

		StringBuilder retValue = new StringBuilder();

		retValue.append(super.toString()).append(TAB).append("id = ").append(this.getId()).append(TAB).append("cdg = ")
				.append(this.getCdg()).append(TAB).append("nomeReferente = ").append(this.getNomeReferente())
				.append(TAB).append("cognomeReferente = ").append(this.getCognomeReferente()).append("assenteAl = ")
				.append(this.getAssenteAl()).append(TAB).append("assenteDal = ").append(this.getAssenteDal())
				.append(TAB).append("note = ").append(this.getNote()).append(TAB).append("status = ")
				.append("created = ").append(this.getCreated()).append(TAB)
				.append("creator = ").append(this.getCreator()).append(TAB).append("modified = ")
				.append(this.getModified()).append(TAB).append("modifier = ").append(this.getModifier());

		return retValue.toString();
	}

	/**
	 * Clone method
	 * 
	 */
	@Override
	public Famiglia clone()
	{
		Famiglia clone = new Famiglia();

		clone.setId(this.getId());
		clone.setNomeReferente(this.getNomeReferente());
		clone.setCognomeReferente(this.getCognomeReferente());
		clone.setNote(this.getNote());
		clone.setPassword(this.getPassword());
		clone.setAssenteAl(this.getAssenteAl());
		clone.setAssenteDal(this.getAssenteDal());
		clone.setCreated(this.getCreated());
		clone.setCreator(this.getCreator());
		clone.setModified(this.getModified());
		clone.setModifier(this.getModifier());

		return clone;
	}

	public long getId()
	{
		return id;
	}

	public void setId(long id)
	{
		this.id = id;
	}

	public String getCdg()
	{
		return cdg;
	}

	public void setCdg(String cdg)
	{
		this.cdg = cdg;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getCognomeReferente()
	{
		return cognomeReferente;
	}

	public void setCognomeReferente(String cognomeReferente)
	{
		this.cognomeReferente = cognomeReferente;
	}

	public String getNomeReferente()
	{
		return nomeReferente;
	}

	public void setNomeReferente(String nomeReferente)
	{
		this.nomeReferente = nomeReferente;
	}

	public String getNote()
	{
		return note;
	}

	public void setNote(String note)
	{
		this.note = note;
	}

	public Date getAssenteDal()
	{
		return assenteDal;
	}

	public void setAssenteDal(Date assenteDal)
	{
		this.assenteDal = assenteDal;
	}

	public Date getAssenteAl()
	{
		return assenteAl;
	}

	public void setAssenteAl(Date assenteAl)
	{
		this.assenteAl = assenteAl;
	}

}
